package com.huawei.java.model;

import java.util.LinkedList;
import java.util.List;
import java.util.Objects;


public class SiteNode implements Comparable<SiteNode>{
    private String name;

    private int totalBandwidth;

    private int currentBandwidth;

    private List<ClientNode> validClient = new LinkedList<>();

    private boolean isUsed;

    // 使用次数
    private int availableNum;

    public SiteNode(String name) {
        this.name = name;
    }

    public int getTotalBandwidth() {
        return totalBandwidth;
    }

    public void setTotalBandwidth(int totalBandwidth) {
        this.totalBandwidth = totalBandwidth;
    }

    public int getCurrentBandwidth() {
        return currentBandwidth;
    }

    public void setCurrentBandwidth(int currentBandwidth) {
        this.currentBandwidth = currentBandwidth;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<ClientNode> getValidClient() {
        return validClient;
    }

    public void setValidClient(List<ClientNode> validClient) {
        this.validClient = validClient;
    }

    public int getAvailableNum() {
        return availableNum;
    }

    public void setAvailableNum(int availableNum) {
        this.availableNum = availableNum;
    }

    public boolean isUsed() {
        return isUsed;
    }

    public void setUsed(boolean used) {
        isUsed = used;
    }

    public int existUsedCount() {
        if (getAvailableNum() > 0) {
            return 0;
        }
        return 1;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SiteNode siteNode = (SiteNode) o;
        return Objects.equals(name, siteNode.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    @Override
    public String toString() {
        return "SiteNode{" +
                "name='" + name + '\'' +
                ", totalBandwidth=" + totalBandwidth +
                ", currentBandwidth=" + currentBandwidth +
                ", validClient=" + validClient +
                ", availableNum=" + availableNum +
                ", isUsed=" + isUsed +
                '}';
    }

    @Override
    public int compareTo(SiteNode o) {
        int i = o.getValidClient().size() - this.getValidClient().size();
        return i == 0 ? 1 : i;
    }
}
